<?xml version="1.0" encoding="utf-8" ?>
<sqlMap namespace='test' xmlns='http://ibatis.apache.org/mapping' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
  <alias>
    <typeAlias alias='test' assembly='Janus.Mes.POCO.dll' type='Janus.Mes.POCO.test' />
  </alias>
  <resultMaps>
    <resultMap id='testResult' class='test'>
	<result property='code' column='code' /> 
		</resultMap>
  </resultMaps>  
  <statements>
  <sql id="UpdaterConditions">  
  <dynamic prepend="SET">
    	<isPropertyAvailable prepend="" property="code">
        <isNotEmpty prepend="," property="code">
		          [code]=#code#
		          </isNotEmpty>
      </isPropertyAvailable>	
	  	 </dynamic>
    </sql>
	<sql id="WhereConditions">
	 <dynamic prepend="WHERE">
	 	 <isPropertyAvailable prepend="" property="code">
        <isNotEmpty prepend="AND" property="code">
		          [code]=#code#
		          </isNotEmpty>
      </isPropertyAvailable>
	  </dynamic> 
    </sql>
	<sql id="InsertPublic">
      INSERT INTO test(
	     <dynamic prepend=" ">
       	   <isPropertyAvailable prepend="" property="code">
        <isNotEmpty prepend="," property="code">
          [code]
        </isNotEmpty>
      </isPropertyAvailable>
	  </dynamic>
      )
      VALUES
      (
	   <dynamic prepend=" ">
      	<isPropertyAvailable prepend="" property="code">
        <isNotEmpty prepend="," property="code">		
         #code#		
        </isNotEmpty>
      </isPropertyAvailable>
	  </dynamic>
      )
    </sql>
	<!-- Insert statement:新增Mapper-->
    <insert id='Insert' parameterClass='test'>
      <include refid="InsertPublic"/>
    </insert>
    <!--Update statement:修改Mapper-->
    <update id='Update' parameterClass='test'>
      UPDATE [test] 
      <include refid="UpdaterConditions"/>
      WHERE 1=1
	      </update>
    <update id='UpdateSetion' parameterClass='hashtable'>
      UPDATE [test] 
      <include refid="UpdaterConditions"/>
      WHERE $conditions$
    </update>
	<update id='Save' parameterClass='test'>
      IF NOT EXISTS(SELECT 1 FROM [test] WHERE 1=1 )
      BEGIN
      <include refid="InsertPublic"/>
      END
      ELSE
      BEGIN
      UPDATE test 
      <include refid="UpdaterConditions"/>
      WHERE  1=1
	        END
    </update>
	<delete id='Delete' parameterClass='hashtable'>
      DELETE FROM [test] WHERE	  
        <![CDATA[  
	 
        ]]>
    </delete>
    <delete id='DeleteWhere' parameterClass='string'>
      DELETE FROM [test] WHERE $value$
    </delete>

    <!-- select by key statement:-->
    <select id='FindOne' parameterClass='hashtable' resultClass='test'>
      SELECT * FROM test WHERE      
        <![CDATA[
		
        ]]>
    </select>
    <select id='FindAllCondition' parameterClass='string' resultClass='test'>
      SELECT * FROM [test] WHERE $value$
    </select>
    <select id='FindScalar' parameterClass='hashtable' resultClass='test'>
      SELECT * FROM [test] WHERE $conditions$
    </select>
    
    <select id='FindAllCount' parameterClass='string' resultClass='int'>
      SELECT COUNT(1) FROM [test] WHERE $value$
    </select>
    <select id='FindByPage' parameterClass='string' resultClass='test'>
      SELECT * FROM [test] WHERE $value$
    </select>
  </statements>
</sqlMap>
